﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Chefbook.DataObjects;
using System.Globalization;
using Chefbook.ViewModels;

namespace Chefbook.UserActions
{
    /// <summary>
    /// An action to add a recipe to a category
    /// </summary>
    public class AddRecipeToCategoryAction : UserActionBase
    {
        private RecipeViewModel recipe;
        private CategoryViewModel category;

        /// <summary>
        /// Creates a new action to add a recipe to a category
        /// </summary>
        /// <param name="recipeToAdd">The recipe to add</param>
        /// <param name="categoryToAddTo">The category to add to</param>
        public AddRecipeToCategoryAction(RecipeViewModel recipeToAdd, CategoryViewModel categoryToAddTo)
            : base()
        {
            recipe = recipeToAdd;
            category = categoryToAddTo;
        }

        /// <summary>
        /// Adds the recipe to the new category
        /// </summary>
        public override void DoAction()
        {
            base.DoAction();
            category.AddRecipe(recipe);
        }

        /// <summary>
        /// Removes the recipe from the new category
        /// </summary>
        public override void UndoAction()
        {
            base.UndoAction();
            category.RemoveRecipe(recipe);
        }

        /// <summary>
        /// Returns a user-friendly string describing the action
        /// </summary>
        /// <returns>A user-friendly string describing the action</returns>
        public override string ToString()
        {
            return string.Format(CultureInfo.CurrentUICulture, "Add Recipe '{0}' To Category '{1}'", recipe, category);
        }
    }
}
